<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="./css/login.css" type="text/css">
    <script src="./lib/layui/layui.js" type="text/javascript"></script>

    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/login.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>

</head>
<style>
    .father{width:1000px;height:auto;margin:0 auto;}
    .layui-input{width:300px;line-height:40px;}
    .login-main{margin-top:300px;margin-left:350px;width:300px;height:400px;/* border:1px solid #e6e6e6; */}
    .layui-form{margin-top:20px;}
    .layui-input-inline{margin-top:30px;}
    button{width:300px;}
</style>
<body>

<div class="father">
    <div class="login-main">
        ，<p style="color:#009688;font-size:25px;text-align:center;">用户注册</p>
        <form class="layui-form">
            <input type="hidden" name="uid">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="uname" required lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                       class="layui-input">
            </div>
            <br>
            <div class="layui-input-inline">
                <input type="password" name="upassword" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
                       class="layui-input">
            </div>
            <br>
            <div class="layui-input-inline">
                <input type="password" name="repassword" required lay-verify="required" placeholder="请再次输入密码" autocomplete="off"
                       class="layui-input">
            </div>
            <br>
            <div class="layui-input-inline">
                <input type="email" name="uemail" required lay-verify="required" placeholder="请输入邮箱" autocomplete="off"
                       class="layui-input" id="email">
            </div>
            <div class="layui-input-inline">
                <input type="text" name="uphone" required lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                       class="layui-input">
            </div>

            <div class="layui-input-inline">
                <select name="umark" lay-verify="" >==
                    <option value="" disabled selected>请选择你想要的教学方式</option>
                    <option value="010">线上多人教学</option>
                    <option value="021">线下1V1教学</option>

                </select>
            </div>


            <br>
            <div class="layui-input-inline login-btn">
                <button lay-submit lay-filter="login" class="layui-btn" >注册</button>
            </div>
            <hr/>
        </form>
    </div>
</div>


<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        form.on('submit(login)',
            function isEmail(email) {
                var strEmail = document.getElementById(email).value;
                if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
                    document.getElementById('email').innerText = "邮箱格式正确";
                    b = true;
                    return true;
                } else {
                    document.getElementById('email').innerText = "邮箱格式错误！";
                    document.getElementById(email).focus();
                    b = false;
                    return false;
                }

            });
    })


    layui.use(['form','layer','jquery'], function () {

        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(login)',function (obj) {
            // console.log(data.field);
            var field=obj.field;
            //确认密码
            if(field.upassword !== field.repassword){
                layer.msg('两次密码输入不一致');
            }else {
                $.ajax({
                url: '/user/add',
                data: field,
                dataType: 'text',
                type: 'Post',
                success: function (data) {
                    if (data == 1) {
                   alert("注册成功！进入到管理员界面")
                        location.href = "./yuangongindex.html";
//                    }else{
//                        layer.msg('错误');
                    }else if(data == 0){
                        layer.msg('用户名已存在');
                    }

                }
//            });
            });

        }
            return false;
        });
    });
</script>
</body>
</html>